<template>
  <div>
    <!--地图-->
    <SuperMapLayerMap v-if="completeRefreshData==true"
              :map="map"
              :allRadioIndexData="allRadioIndexData"
              :allListData="allListData"
              :taskGeom="props.taskGeom"
              :typeCodeDataList="typeCodeDataList"
              :resetClearAllBool="resetClearAllBool"
              :dataTypeInfoArray="dataTypeInfoArray"
              :queryGeomText="queryGeomText"
              :clickLonLatArr="clickLonLatArr"
              @getDetailDataById="getDetailDataById"
              @getLegendHtml="getLegendHtml"
              @getAllTempLayersSetList="getAllTempLayersSetList"
    ></SuperMapLayerMap>
    <!--图层图例-->
    <div v-if="showHideLegendDivBool" class="layerMap-legend">
      <!--滚动条-->
      <el-scrollbar max-height="500px">
        <p>图例</p>
        <div><div style="width: 16px;height: 16px;float: left;margin-top: 3px;border: 2px solid #668B8B;"></div><div style="margin-left: 25px;">任务区域</div></div>
        <div v-for="item in layerShowHideArray" :key="item.code" v-show="item.show" v-html="item.legendHtml">
        </div>
      </el-scrollbar>
    </div>
  </div>
</template>

<script setup name="SuperMapLayer">
import SuperMapLayerMap from '@/map/components/superMapLayer/map.vue';
import { iServerHttp } from "@/map/projMap.js";

const props = defineProps(['map','layerDataTypeList','taskGeom','resetClearAllBool','geomText','clickLonLat','resultLegend']);
const emits = defineEmits(['getAllTempLayersSetList'])
const showHideLegendDivBool = ref(false);//是否显示图例
const layerShowHideArray = ref([]);//图层是否显示数组

/*地图传参start*/
const completeRefreshData = ref(false);//防止刷新后地图不显示
const resetClearAllBool = ref(false);//是否重置清空全部图层数组
const queryGeomText = ref("");//限制查询范围的空间数据wkt
const clickLonLatArr = ref([]);//获取点击地图经纬度
const allListData = ref([]);//地图显示数据列表
const allRadioIndexData = ref([]);//全部序号列表
//数据图层显示列表
const collapseLayerData = ref([]);
//选择图层的版本号数据列表
const typeCodeDataList = ref([]);
//是否显示图层表格数据列表
const allTableDataBool = ref(false);
//图层表格数据列表
const allTableDataList = ref([]);
//表头字段数据列表
const allTableTitleList = ref([]);
//是否为空间数据
const isSpatialDataBool = ref(false);
//总数据量
const total = ref(0);
//当前数据类型图层名称
const currentLayerName = ref("");
//当前数据类型code
const currentLayerCode = ref("");
//当前数据版本号
const currentVersionCode = ref("");
//选中1条数据的ID
const selectId = ref("");
//数据类型
const dataTypeInfoArray = ref([
  //建筑物确定评估
  {database:"fxfzfxqh", name: '结构破坏-确定评估', code: 'seismicEd', table:"fxqh_resist_earthquakes_calculation_ed",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_resist_earthquakes_calculation_ed@fxfzfxqh",zIndex:6,fieldId:"id"},
  // {database:"fxfzfxqh", name: '人员伤亡-确定评估', code: 'personCasualtiesEd', table:"fxqh_casualties_calculation_ed",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_casualties_calculation_ed@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '人员伤亡-确定评估-白天死亡', code: 'personCasualtiesEd_day_death', table:"fxqh_casualties_calculation_ed_day_death",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_casualties_calculation_ed_day_death@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '人员伤亡-确定评估-白天重伤', code: 'personCasualtiesEd_day_injure', table:"fxqh_casualties_calculation_ed_day_injure",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_casualties_calculation_ed_day_injure@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '人员伤亡-确定评估-夜间死亡', code: 'personCasualtiesEd_night_death', table:"fxqh_casualties_calculation_ed_night_death",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_casualties_calculation_ed_night_death@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '人员伤亡-确定评估-夜间重伤', code: 'personCasualtiesEd_night_injure', table:"fxqh_casualties_calculation_ed_night_injure",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_casualties_calculation_ed_night_injure@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '经济损失-确定评估', code: 'economicLossesEd', table:"fxqh_economic_loss_calculation_ed",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_economic_loss_calculation_ed@fxfzfxqh",zIndex:6,fieldId:"id"},
  //建筑物概率评估
  {database:"fxfzfxqh", name: '结构破坏-概率评估', code: 'seismicPd', table:"fxqh_resist_earthquakes_calculation_pd",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_resist_earthquakes_calculation_pd@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '人员伤亡-概率评估', code: 'personCasualtiesPd', table:"fxqh_casualties_calculation_pd",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_casualties_calculation_pd@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '经济损失-概率评估', code: 'economicLossesPd', table:"fxqh_economic_loss_calculation_pd",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_economic_loss_calculation_pd@fxfzfxqh",zIndex:6,fieldId:"id"},
  //单指标风险区划--确定评估风险区划--结构破坏
  {database:"fxfzfxqh", name: '单指标风险区划-确定评估风险区划', code: 'singleRiskZonationConfirm', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result@fxfzfxqh",zIndex:6,fieldId:"id"},
  //单指标风险区划--确定评估风险区划--结构破坏
  {database:"fxfzfxqh", name: '单指标风险区划--结构破坏-确定评估风险区划1', code: 'singleRiskZonationConfirmKznl1', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_kznl_1@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--结构破坏-确定评估风险区划2', code: 'singleRiskZonationConfirmKznl2', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_kznl_2@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--结构破坏-确定评估风险区划3', code: 'singleRiskZonationConfirmKznl3', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_kznl_3@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--结构破坏-确定评估风险区划4', code: 'singleRiskZonationConfirmKznl4', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_kznl_4@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--结构破坏-确定评估风险区划5', code: 'singleRiskZonationConfirmKznl5', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_kznl_5@fxfzfxqh",zIndex:6,fieldId:"id"},
  //单指标风险区划--确定评估风险区划--人员伤亡
  {database:"fxfzfxqh", name: '单指标风险区划--人员伤亡-确定评估风险区划1', code: 'singleRiskZonationConfirmRk1', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_rk_1@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--人员伤亡-确定评估风险区划2', code: 'singleRiskZonationConfirmRk2', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_rk_2@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--人员伤亡-确定评估风险区划3', code: 'singleRiskZonationConfirmRk3', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_rk_3@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--人员伤亡-确定评估风险区划4', code: 'singleRiskZonationConfirmRk4', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_rk_4@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--人员伤亡-确定评估风险区划5', code: 'singleRiskZonationConfirmRk5', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_rk_5@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--人员伤亡-确定评估风险区划6--新疆、青海和西藏地区确定评估风险区划1', code: 'singleRiskZonationConfirmRk6', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_rk_1@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--人员伤亡-确定评估风险区划7--新疆、青海和西藏地区确定评估风险区划2', code: 'singleRiskZonationConfirmRk7', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_rk_2@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--人员伤亡-确定评估风险区划8--新疆、青海和西藏地区确定评估风险区划3', code: 'singleRiskZonationConfirmRk8', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_rk_3@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--人员伤亡-确定评估风险区划9--新疆、青海和西藏地区确定评估风险区划4', code: 'singleRiskZonationConfirmRk9', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_rk_4@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--人员伤亡-确定评估风险区划10--新疆、青海和西藏地区确定评估风险区划5', code: 'singleRiskZonationConfirmRk10', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_rk_5@fxfzfxqh",zIndex:6,fieldId:"id"},
  //单指标风险区划--确定评估风险区划--经济损失
  {database:"fxfzfxqh", name: '单指标风险区划--经济损失-确定评估风险区划1', code: 'singleRiskZonationConfirmJj1', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_jj_1@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--经济损失-确定评估风险区划2', code: 'singleRiskZonationConfirmJj2', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_jj_2@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--经济损失-确定评估风险区划3', code: 'singleRiskZonationConfirmJj3', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_jj_3@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--经济损失-确定评估风险区划4', code: 'singleRiskZonationConfirmJj4', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_jj_4@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--经济损失-确定评估风险区划5', code: 'singleRiskZonationConfirmJj5', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_jj_5@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--经济损失-确定评估风险区划6--新疆、青海和西藏地区确定评估风险区划1', code: 'singleRiskZonationConfirmJj6', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_jj_1@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--经济损失-确定评估风险区划7--新疆、青海和西藏地区确定评估风险区划2', code: 'singleRiskZonationConfirmJj7', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_jj_2@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--经济损失-确定评估风险区划8--新疆、青海和西藏地区确定评估风险区划3', code: 'singleRiskZonationConfirmJj8', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_jj_3@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--经济损失-确定评估风险区划9--新疆、青海和西藏地区确定评估风险区划4', code: 'singleRiskZonationConfirmJj9', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_jj_4@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '单指标风险区划--经济损失-确定评估风险区划10--新疆、青海和西藏地区确定评估风险区划5', code: 'singleRiskZonationConfirmJj10', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_assess_ed_qh_result_jj_5@fxfzfxqh",zIndex:6,fieldId:"id"},
  {database:"fxfzfxqh", name: '综合风险区划', code: 'overallRiskZonation', table:"fxqh_assess_ed_qh_result",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/fxqh_composite_assess@fxfzfxqh",zIndex:6,fieldId:"id"},
  //单指标风险区划--概率评估风险区划
  // {database:"fxfzfxqh", name: '单指标风险区划--概率评估风险区划1', code: 'singleRiskZonationProbability1', table:"enter_assess_qh_res",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/enter_assess_qh_res_1@fxfzfxqh",zIndex:6,fieldId:"id"},
  // {database:"fxfzfxqh", name: '单指标风险区划--概率评估风险区划2', code: 'singleRiskZonationProbability2', table:"enter_assess_qh_res",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/enter_assess_qh_res_2@fxfzfxqh",zIndex:6,fieldId:"id"},
  // {database:"fxfzfxqh", name: '单指标风险区划--概率评估风险区划3', code: 'singleRiskZonationProbability3', table:"enter_assess_qh_res",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/enter_assess_qh_res_3@fxfzfxqh",zIndex:6,fieldId:"id"},
  // {database:"fxfzfxqh", name: '单指标风险区划--概率评估风险区划4', code: 'singleRiskZonationProbability4', table:"enter_assess_qh_res",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/enter_assess_qh_res_4@fxfzfxqh",zIndex:6,fieldId:"id"},
  // {database:"fxfzfxqh", name: '单指标风险区划--概率评估风险区划5', code: 'singleRiskZonationProbability5', table:"enter_assess_qh_res",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/enter_assess_qh_res_5@fxfzfxqh",zIndex:6,fieldId:"id"},
  // {database:"fxfzfxqh", name: '单指标风险区划--概率评估风险区划6--新疆、青海和西藏地区确定评估风险区划1', code: 'singleRiskZonationProbability6', table:"enter_assess_qh_res",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/enter_assess_qh_res_1@fxfzfxqh",zIndex:6,fieldId:"id"},
  // {database:"fxfzfxqh", name: '单指标风险区划--概率评估风险区划7--新疆、青海和西藏地区确定评估风险区划2', code: 'singleRiskZonationProbability7', table:"enter_assess_qh_res",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/enter_assess_qh_res_2@fxfzfxqh",zIndex:6,fieldId:"id"},
  // {database:"fxfzfxqh", name: '单指标风险区划--概率评估风险区划8--新疆、青海和西藏地区确定评估风险区划3', code: 'singleRiskZonationProbability8', table:"enter_assess_qh_res",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/enter_assess_qh_res_3@fxfzfxqh",zIndex:6,fieldId:"id"},
  // {database:"fxfzfxqh", name: '单指标风险区划--概率评估风险区划9--新疆、青海和西藏地区确定评估风险区划4', code: 'singleRiskZonationProbability9', table:"enter_assess_qh_res",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/enter_assess_qh_res_4@fxfzfxqh",zIndex:6,fieldId:"id"},
  // {database:"fxfzfxqh", name: '单指标风险区划--概率评估风险区划10--新疆、青海和西藏地区确定评估风险区划5', code: 'singleRiskZonationProbability10', table:"enter_assess_qh_res",url:iServerHttp()+"/iserver/services/map-fxfzfxqh/rest/maps/enter_assess_qh_res_5@fxfzfxqh",zIndex:6,fieldId:"id"},
]);
//根据ID查询数据属性表
const getDetailDataById = (temp)=>{
  console.log("开始根据ID查询数据属性表");
  let typeCode = temp.typeCode;
  let id = temp.id;
  let params = {
    typeCode : typeCode,//三级数据类别（数据表）code
    id : id,
  }
  allTableDataBool.value = false;
  allTableDataList.value = [];//清空根据ID查询数据属性表
  allTableTitleList.value = [];
  //获取数据图层名称
  currentLayerName.value = getDictItemNameByCode(typeCode);
  //当前数据类型code
  currentLayerCode.value = typeCode;
  //当前数据版本号
  currentVersionCode.value = "";
  //选中1条数据的ID
  selectId.value = id;
  //是否为空间数据
  isSpatialDataBool.value = true;
}
//图例
const getLegendHtml = (obj)=>{
  console.log("getLegendHtml");
  console.log(obj);
  if (obj != null) {
    layerShowHideArray.value = [{
      name: obj.name,
      show: obj.show,
      legendHtml: obj.legendHtml
    }];
    showHideLegendDivBool.value = true;// 打开图例面板
  }
  //图层显示隐藏数组
  // let showHideArray = layerShowHideArray.value;
  // if(obj!=null){
  //   for(let i=0;i<showHideArray.length;i++){
  //     if(showHideArray[i].name==obj.name){
  //       let code = showHideArray[i].code;
  //       let legendHtml = obj.legendHtml;
  //       //设置图例文字样式
  //       legendHtml = setLegendHtml(obj.name,code,legendHtml);
  //       console.log(legendHtml);
  //       showHideArray[i].show = obj.show;
  //       showHideArray[i].legendHtml = legendHtml;//显示图例
  //       break;
  //     }
  //   }
  //   //是否显示图例
  //   let bool = false;
  //   for(let i=0;i<showHideArray.length;i++){
  //     if(showHideArray[i].show){
  //       bool = true;
  //       break;
  //     }
  //   }
  //   showHideLegendDivBool.value = bool;
  // }else{//清空图例
  //   //是否显示图例
  //   for(let i=0;i<showHideArray.length;i++){
  //     showHideArray[i].show = false;
  //   }
  //   showHideLegendDivBool.value = false;
  // }
}
//获取全部图层信息列表
const getAllTempLayersSetList = (obj)=>{
  console.log("getAllTempLayersSetList");
  console.log(obj);
  emits('getAllTempLayersSetList', obj);
}
/*地图传参end*/

//设置图例
function setLayerShowHideArray(){
  let showHideArray = [];
  let dataTypeArray = dataTypeInfoArray.value;
  for(let i=0;i<dataTypeArray.length;i++){
    let item = dataTypeArray[i];
    showHideArray.push({ code: item.code, name: item.name, show:false,legendHtml:"" });
  }
  layerShowHideArray.value = showHideArray;
}

//设置图例文字样式
function setLegendHtml(name,code,legendHtml){
  let list = props.layerDataTypeList;
  if(list){
    for(let i=0;i<list.length;i++){
      let level3DataType = list[i].level3DataType;//数据类别三级code
      if(level3DataType==code){
        let legendLabel = list[i].legendLabel;//图例文字
        if(legendLabel){
          legendHtml = legendHtml.replace(name,legendLabel);//替换图例文字
        }
        break;
      }
    }
  }

  return legendHtml;
}

//获取数据图层显示列表
const getAllTreeData = ()=>{
  /**
   * dictCode :类别code 数据类别的dictItemCode
   */
  let list = [
    {
      dictItemCode:"buildingConfirm",
      dictItemName:"建筑物确定评估",
      children:[
        {dictItemCode:"seismicEd",dictItemName:"结构破坏-确定评估"},
        // {dictItemCode:"personCasualtiesEd",dictItemName:"人员伤亡-确定评估"},
        {dictItemCode:"personCasualtiesEd_day_death",dictItemName:"人员伤亡-确定评估-白天死亡"},
        {dictItemCode:"personCasualtiesEd_day_injure",dictItemName:"人员伤亡-确定评估-白天重伤"},
        {dictItemCode:"personCasualtiesEd_night_death",dictItemName:"人员伤亡-确定评估-夜间死亡"},
        {dictItemCode:"personCasualtiesEd_night_injure",dictItemName:"人员伤亡-确定评估-夜间重伤"},
        {dictItemCode:"economicLossesEd",dictItemName:"经济损失-确定评估"}
      ]
    },
    {
      dictItemCode:"buildingProbability",
      dictItemName:"建筑物概率评估",
      children:[
        {dictItemCode:"seismicPd",dictItemName:"结构破坏-概率评估"},
        {dictItemCode:"personCasualtiesPd",dictItemName:"人员伤亡-概率评估"},
        {dictItemCode:"economicLossesPd",dictItemName:"经济损失-概率评估"}
      ]
    },
    {
      dictItemCode:"singleRiskZonation",
      dictItemName:"单指标风险区划",
      children:[
        //结构破坏
        {dictItemCode:"singleRiskZonationConfirmKznl1",dictItemName:"单指标风险区划--结构破坏-确定评估风险区划1"},
        {dictItemCode:"singleRiskZonationConfirmKznl2",dictItemName:"单指标风险区划--结构破坏-确定评估风险区划2"},
        {dictItemCode:"singleRiskZonationConfirmKznl3",dictItemName:"单指标风险区划--结构破坏-确定评估风险区划3"},
        {dictItemCode:"singleRiskZonationConfirmKznl4",dictItemName:"单指标风险区划--结构破坏-确定评估风险区划4"},
        {dictItemCode:"singleRiskZonationConfirmKznl5",dictItemName:"单指标风险区划--结构破坏-确定评估风险区划5"},
        //人员伤亡
        {dictItemCode:"singleRiskZonationConfirmRk1",dictItemName:"单指标风险区划--人员伤亡-确定评估风险区划1"},
        {dictItemCode:"singleRiskZonationConfirmRk2",dictItemName:"单指标风险区划--人员伤亡-确定评估风险区划2"},
        {dictItemCode:"singleRiskZonationConfirmRk3",dictItemName:"单指标风险区划--人员伤亡-确定评估风险区划3"},
        {dictItemCode:"singleRiskZonationConfirmRk4",dictItemName:"单指标风险区划--人员伤亡-确定评估风险区划4"},
        {dictItemCode:"singleRiskZonationConfirmRk5",dictItemName:"单指标风险区划--人员伤亡-确定评估风险区划5"},
        {dictItemCode:"singleRiskZonationConfirmRk6",dictItemName:"单指标风险区划--人员伤亡-确定评估风险区划6--新疆、青海和西藏地区确定评估风险区划1"},
        {dictItemCode:"singleRiskZonationConfirmRk7",dictItemName:"单指标风险区划--人员伤亡-确定评估风险区划7--新疆、青海和西藏地区确定评估风险区划2"},
        {dictItemCode:"singleRiskZonationConfirmRk8",dictItemName:"单指标风险区划--人员伤亡-确定评估风险区划8--新疆、青海和西藏地区确定评估风险区划3"},
        {dictItemCode:"singleRiskZonationConfirmRk9",dictItemName:"单指标风险区划--人员伤亡-确定评估风险区划9--新疆、青海和西藏地区确定评估风险区划4"},
        {dictItemCode:"singleRiskZonationConfirmRk10",dictItemName:"单指标风险区划--人员伤亡-确定评估风险区划10--新疆、青海和西藏地区确定评估风险区划5"},
        //经济损失
        {dictItemCode:"singleRiskZonationConfirmJj1",dictItemName:"单指标风险区划--经济损失-确定评估风险区划1"},
        {dictItemCode:"singleRiskZonationConfirmJj2",dictItemName:"单指标风险区划--经济损失-确定评估风险区划2"},
        {dictItemCode:"singleRiskZonationConfirmJj3",dictItemName:"单指标风险区划--经济损失-确定评估风险区划3"},
        {dictItemCode:"singleRiskZonationConfirmJj4",dictItemName:"单指标风险区划--经济损失-确定评估风险区划4"},
        {dictItemCode:"singleRiskZonationConfirmJj5",dictItemName:"单指标风险区划--经济损失-确定评估风险区划5"},
        {dictItemCode:"singleRiskZonationConfirmJj6",dictItemName:"单指标风险区划--经济损失-确定评估风险区划6--新疆、青海和西藏地区确定评估风险区划1"},
        {dictItemCode:"singleRiskZonationConfirmJj7",dictItemName:"单指标风险区划--经济损失-确定评估风险区划7--新疆、青海和西藏地区确定评估风险区划2"},
        {dictItemCode:"singleRiskZonationConfirmJj8",dictItemName:"单指标风险区划--经济损失-确定评估风险区划8--新疆、青海和西藏地区确定评估风险区划3"},
        {dictItemCode:"singleRiskZonationConfirmJj9",dictItemName:"单指标风险区划--经济损失-确定评估风险区划9--新疆、青海和西藏地区确定评估风险区划4"},
        {dictItemCode:"singleRiskZonationConfirmJj10",dictItemName:"单指标风险区划--经济损失-确定评估风险区划10--新疆、青海和西藏地区确定评估风险区划5"},
        // {dictItemCode:"singleRiskZonationProbability1",dictItemName:"单指标风险区划--概率评估风险区划1"},
        // {dictItemCode:"singleRiskZonationProbability2",dictItemName:"单指标风险区划--概率评估风险区划2"},
        // {dictItemCode:"singleRiskZonationProbability3",dictItemName:"单指标风险区划--概率评估风险区划3"},
        // {dictItemCode:"singleRiskZonationProbability4",dictItemName:"单指标风险区划--概率评估风险区划4"},
        // {dictItemCode:"singleRiskZonationProbability5",dictItemName:"单指标风险区划--概率评估风险区划5"},
        // {dictItemCode:"singleRiskZonationProbability6",dictItemName:"单指标风险区划--概率评估风险区划6--新疆、青海和西藏地区确定评估风险区划1"},
        // {dictItemCode:"singleRiskZonationProbability7",dictItemName:"单指标风险区划--概率评估风险区划7--新疆、青海和西藏地区确定评估风险区划2"},
        // {dictItemCode:"singleRiskZonationProbability8",dictItemName:"单指标风险区划--概率评估风险区划8--新疆、青海和西藏地区确定评估风险区划3"},
        // {dictItemCode:"singleRiskZonationProbability9",dictItemName:"单指标风险区划--概率评估风险区划9--新疆、青海和西藏地区确定评估风险区划4"},
        // {dictItemCode:"singleRiskZonationProbability10",dictItemName:"单指标风险区划--概率评估风险区划10--新疆、青海和西藏地区确定评估风险区划5"},
      ]
    },
    {
      dictItemCode:"overallRiskZonation1",
      dictItemName:"综合风险区划",
      children:[
        {dictItemCode:"overallRiskZonation",dictItemName:"综合风险区划"},
      ]
    },
  ];
  let collapseLayerDataArray = [];
  let typeCodeDataArray = [];
  let allRadioIndexArray = [];
  if(list!=null && list.length>0){
    for(let i=0;i<list.length;i++){
      let data = list[i];
      let childrenData = [];
      let children = data.children;
      for(let j=0;j<children.length;j++){
        /*let bool = false;
        if(children[j].isSpatialData==1){//空间数据
          bool = true;
        }*/
        let bool = true;//空间数据
        childrenData.push({
          name: children[j].dictItemName,
          spaceBool:bool,//是否空间数据
          dictItemCode: children[j].dictItemCode,
        });
        //选择图层的版本号数据列表
        typeCodeDataArray.push({
          name: children[j].dictItemName,
          typeCodeSelectData:[],
          dictItemCode: children[j].dictItemCode,
          spaceBool:bool,//是否空间数据
          fitBool:true,//是否缩放到范围
          queryGeomBool:false,//是否限制查询范围
        });
        //全部序号列表
        allRadioIndexArray.push(children[j].dictItemCode);//三级数据类别
      }
      let collapseData = {
        value:data.dictItemCode,
        label: data.dictItemName,
        children: childrenData,
        dictItemCode: data.dictItemCode,
      }
      collapseLayerDataArray.push(collapseData);
    }
  }

  //数据图层显示列表
  collapseLayerData.value = collapseLayerDataArray;
  //选择图层的版本号数据列表
  typeCodeDataList.value = typeCodeDataArray;
  console.log("typeCodeDataList.value");
  console.log(typeCodeDataList.value);
  //全部序号列表
  allRadioIndexData.value = allRadioIndexArray;
  //显示地图模块
  completeRefreshData.value = true;
}

//根据三级数据类别获取版本数据
const getLayerInfoByDictItemCode = (dictItemCode) => {
  let data = null;
  let datalist = typeCodeDataList.value;
  for(let i=0;i<datalist.length;i++){
    if(datalist[i].dictItemCode==dictItemCode){
      data = datalist[i];
      break;
    }
  }
  console.log("根据三级数据类别获取版本数据");
  console.log(typeCodeDataList.value);
  console.log(data);
  return data;
}

//根据三级数据类别（数据表）code获取数据图层名称
const getDictItemNameByCode = (typeCode) => {
  let dictItemName = "";
  let list = typeCodeDataList.value;
  for(let i=0;i<list.length;i++){
    if(list[i].dictItemCode==typeCode){
      dictItemName = list[i].name;
      break;
    }
  }

  return dictItemName;
}

//查询版本号对应图层数据（基础数据系统）
const getDataByVersionCode = (versionCode,typeCode,spatialBool,tifFileName)=>{
  console.log("开始查询版本号对应图层数据");
  allTableDataBool.value = false;
  allTableDataList.value = [];//清空图层表格数据列表
  allTableTitleList.value = [];
  //获取数据图层名称
  currentLayerName.value = getDictItemNameByCode(typeCode);
  //当前数据类型code
  currentLayerCode.value = typeCode;
  //当前数据版本号
  currentVersionCode.value = versionCode;
  //选中1条数据的ID
  selectId.value = "";

  if (typeCode == "demgcsj") {//高程
    allListData.value = [typeCode,versionCode,[],true,tifFileName];//显示超图图层
  }else{
    allListData.value = [typeCode,versionCode,[],true,null];//显示超图图层
  }
}

//查询版本号对应图层数据（业务系统）
const getDataByVersionCodeYw = (versionCode,typeCode,spatialBool,tifFileName)=>{
  console.log("开始查询版本号对应图层数据");
  allTableDataBool.value = false;
  allTableDataList.value = [];//清空图层表格数据列表
  allTableTitleList.value = [];
  //获取数据图层名称
  currentLayerName.value = getDictItemNameByCode(typeCode);
  //当前数据类型code
  currentLayerCode.value = typeCode;
  //当前数据版本号
  currentVersionCode.value = versionCode;
  //选中1条数据的ID
  selectId.value = "";

  allListData.value = [typeCode,versionCode,[],true,tifFileName];//显示超图图层
}

//设置图层选择的版本号列表（添加、移除）并查询图层数据
function setActiveTypeCodeList(versionCode,typeCode,showBool,isYw,tifFileName){
  //根据三级数据类别获取版本数据
  let data = getLayerInfoByDictItemCode(typeCode);
  if(data!=null && versionCode){
    let typeCodeSelectArray = data.typeCodeSelectData;
    let bool = null;//是否添加版本号
    //添加、移除版本号
    // if (!typeCodeSelectArray.includes(versionCode)) {
      if(showBool){
        typeCodeSelectArray.push(versionCode);//添加
        bool = true;
      }
    // } else {
    //   typeCodeSelectArray.forEach((id, index) => {
    //     if (id === versionCode) {
    //       if(showBool==false){
    //         typeCodeSelectArray.splice(index, 1);//移除
    //         bool = false;
    //       }
    //     }
    //   });
    // }
    console.log("设置图层选择的版本号列表");
    console.log(typeCodeSelectArray);
    //设置图层对应的选择版本号列表
    data.typeCodeSelectData = typeCodeSelectArray;
    //是否为空间数据
    isSpatialDataBool.value = data.spaceBool;
    resetClearAllBool.value = false;//是否重置清空全部图层数组
    console.log("showBool:"+showBool+",bool:"+bool);
    //空间数据
    if(showBool && bool){//添加版本号
      //根据图层类型查询图层版本号数据
      if(isYw){
        //查询版本号对应图层数据（业务系统）
        getDataByVersionCodeYw(versionCode,typeCode,true,tifFileName);
      }else{
        //查询版本号对应图层数据（基础数据系统）
        getDataByVersionCode(versionCode,typeCode,true,tifFileName);
      }
      return true;
    }else if(showBool==false && bool==false){//移除版本号
      allListData.value = [typeCode,versionCode,[],false,null];
      allTableDataBool.value = false;
      allTableDataList.value = [];//清空图层表格数据列表
      allTableTitleList.value = [];
      return true;
    }
  }
  return false;
}

//根据code获取超图图层数据类型信息
function getDataTypeInfoByCode(code){
  let dataTypeInfo = null;
  if(code){
    let array = dataTypeInfoArray.value;
    for(let i=0;i<array.length;i++){
      if(code==array[i].code){
        dataTypeInfo = array[i];
        break;
      }
    }
  }

  return dataTypeInfo;
}

//清空全部已选版本号
function clearAllTypeCodeSelectData(){
  let list = typeCodeDataList.value;
  for(let i=0;i<list.length;i++){
    list[i].typeCodeSelectData = [];
  }
}

//根据数据类别code、版本号查询图层
function getLayerByVersionDataType(i){
  let list = props.layerDataTypeList;
  if(i<list.length){
    let level2DataType = list[i].level2DataType;//数据类别二级code
    let level3DataType = list[i].level3DataType;//数据类别三级code
    let versionCode = list[i].versionCode;//版本号："全部"则展示整个图层，null无版本号不展示
    let showBool = list[i].show;//是否显示
    let isYw = list[i].isYw;//是否为业务系统数据，true业务系统，false基础数据系统
    let tifFileName = list[i].tifFileName;//tif文件名称
    console.log("versionCode:"+versionCode+",level3DataType:"+level3DataType+",show:"+showBool);
    //设置图层选择的版本号列表（添加、移除）并查询图层数据
    let returnBool = setActiveTypeCodeList(versionCode,level3DataType,showBool,isYw,tifFileName);
    console.log("returnBool"+returnBool);
    if((i+1)<list.length){
      if(returnBool){
        setTimeout(function(){
          //根据数据类别code、版本号查询图层
          getLayerByVersionDataType(i+1);
        },100);
      }else{
        //根据数据类别code、版本号查询图层
        getLayerByVersionDataType(i+1);
      }
    }
  }
}

//获取图层数据类别code和版本号
const getlayerDataTypeList = watch(() => props.layerDataTypeList, value => {// watch函数监听props.layerDataTypeList
  if(value){
    console.log("获取图层数据类别code和版本号");
    console.log(value);
    setTimeout(function(){
      //根据数据类别code、版本号查询图层
      getLayerByVersionDataType(0);
    },100);
  }
},{immediate:true,deep:true});

//清空全部图层
const resetClearAll = watch(() => props.resetClearAllBool, value => {// watch函数监听props.resetClearAllBool
  if(value){
    resetClearAllBool.value = true;//清空全部图层
    clearAllTypeCodeSelectData();//清空全部已选版本号
    getLegendHtml(null);//清空图例
  }
},{immediate:true});

//限制查询范围
const setQueryGeomText = watch(() => props.geomText, value => {// watch函数监听props.geomText
  if(value){
    queryGeomText.value = value;
  }else{
    queryGeomText.value = "";
  }
},{immediate:true});

//获取点击地图经纬度
const getClickLonLat = watch(() => props.clickLonLat, value => {// watch函数监听props.clickLonLat
  if(value){
    console.log("传递点击地图经纬度");
    console.log(value);
    clickLonLatArr.value = value;
  }
},{immediate:true});

//计算结果图例
const resultLegendHtml = ref("");
//获取计算结果图例
const getResultLegendHtml = watch(() => props.resultLegend, value => {// watch函数监听props.resultLegend
  if(value){
    console.log("获取计算结果图例");
    console.log(value);
    //计算结果图例
    resultLegendHtml.value = value;
  }
},{immediate:true});

onMounted(() => {
  setLayerShowHideArray();
  getAllTreeData();//获取数据图层显示列表
})
</script>

<style scoped lang="scss">
//图例
.layerMap-legend {
  position: absolute;
  right: 10px;
  bottom: 10px;
  min-height: 50px;
  background: #fff;
  padding: 10px;
  overflow: auto;
  min-width: 200px;
  box-shadow: 0px 0px 20px rgba(0,0,0,0.2);
  border:1px solid #707070;
  border-radius: 4px;
}
.layerMap-legend p:first-child{
  text-align: center;font-weight: bold;
}
</style>